package main

import "fmt"

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

func toIntArray(t *TreeNode) []int {
	r := make([]int, 0, 16)
	r = append(r, t.Val)
	if t.Left != nil {
		r = append(r, toIntArray(t.Left)...)
	}
	if t.Right != nil {
		r = append(r, toIntArray(t.Right)...)
	}
	return r
}

/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
func getAllElements(root1 *TreeNode, root2 *TreeNode) []int {
	list := toIntArray(root1)
	list = append(list, toIntArray(root2)...)

	length := len(list)
	for i := 0; i < length; i++ {
		for j := 0; j < length-i-1; j++ {
			if list[j] > list[j+1] {
				list[j], list[j+1] = list[j+1], list[j]
			}
		}
	}

	return list
}

func L1305() {

	// root1 := &TreeNode{
	// 	Val:   2,
	// 	Left:  &TreeNode{1,nil,nil},
	// 	Right: &TreeNode{4,nil,nil},
	// }

	root2 := &TreeNode{
		Val:   0,
		Left:  &TreeNode{1, nil, nil},
		Right: &TreeNode{3, nil, nil},
	}

	var root1 TreeNode

	fmt.Println(getAllElements(&root1, root2))
}
func main() {

}
